package com.gxh.controller.user;

import com.gxh.dto.UserMachineDTO;
import com.gxh.dto.UserRequestMachineDTO;
import com.gxh.result.Result;
import com.gxh.service.UserMachineService;
import com.gxh.vo.UserMachineDetailVO;
import com.gxh.vo.UserMachineItemVO;
import com.gxh.vo.UserRequestMachineDetailVO;
import com.gxh.vo.UserRequestMachineVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController("userUserMachineController")
@RequestMapping("/gxh/user/user_machine")
@Slf4j
@Api(tags = "用户端设备接口")
public class UserMachineController {

    @Autowired
    private UserMachineService userMachineService;

    /**
     * 用户上传设备
     * @param userMachineDTO
     * @return
     */
    @PostMapping("/upload")
    @ApiModelProperty("用户上传设备")
    public Result upload(@RequestBody UserMachineDTO userMachineDTO){
        log.info("用户上传设备：{}",userMachineDTO);
        userMachineService.upload(userMachineDTO);
        return Result.success();
    }

    /**
     * 用户求购设备
     * @param userRequestMachineDTO
     * @return
     */
    @PostMapping("/request")
    @ApiModelProperty("用户求购设备")
    public Result request(@RequestBody UserRequestMachineDTO userRequestMachineDTO){
        log.info("用户求购设备：{}",userRequestMachineDTO);
        userMachineService.request(userRequestMachineDTO);
        return Result.success();
    }

    /**
     * 用户上传设备列表
     * @param status
     * @return
     */
    @GetMapping("/upload")
    @ApiModelProperty("用户上传设备列表")
    public Result<List<UserMachineItemVO>> list(@RequestParam(required = false) Integer status){
        log.info("用户上传设备记录：{}", status);
        List<UserMachineItemVO> userMachineItemVOList = userMachineService.list(status);
        return Result.success(userMachineItemVOList);
    }

    /**
     * 用户求购设备列表
     * @param status
     * @return
     */
    @GetMapping("/request")
    @ApiModelProperty("用户求购设备列表")
    public Result<List<UserRequestMachineVO>> requestList(@RequestParam(required = false) Integer status){
        log.info("用户求购设备记录：{}", status);
        List<UserRequestMachineVO> userRequestMachineVOList = userMachineService.listRequest(status);
        return Result.success(userRequestMachineVOList);
    }

    /**
     * 用户求购设备详情
     * @param id
     * @return
     */
    @GetMapping("/request/{id}")
    @ApiModelProperty("用户求购设备详情")
    public Result<UserRequestMachineDetailVO> requestDetail(@PathVariable Long id){
        log.info("用户求购设备详情：{}", id);
        UserRequestMachineDetailVO userRequestMachineVO = userMachineService.requestDetail(id);
        return Result.success(userRequestMachineVO);
    }

    @GetMapping("/upload/{id}")
    @ApiModelProperty("用户上传设备详情")
    public Result<UserMachineDetailVO> uploadDetail(@PathVariable Long id){
        log.info("用户上传设备详情：{}", id);
        UserMachineDetailVO userMachineDetailVO = userMachineService.uploadDetail(id);
        return Result.success(userMachineDetailVO);
    }
}
